//用户相关接口
import request from "../../utils/request";

//统一接口
const API = {
  LOGIN_URL: "/login",
  USERINFO_URL: "/getUser",
  CAPTCHA_URL: "/captcha",
  SIGN_URL: "/signup",
  GET_FAVORITE_URL: "/getFavorites",
  UPDATE_USERINFO_URL: "/userInfo",
  GET_USER_URL: "/getUser",
  ADD_FAVORITE_URL: "/addFavorites",
  GET_AGE: "/user/age",
  GET_LOGIN_SIGN: "/user/monthly_stats",
  GET_USER_GENDER: "/user/gender",
  GET_ALL_USER: "/user/getAll",
  RECORD_WEIGHT: "/recordWeight",
  DELETE_USER: "/deleteUser",
  DELETE_USERS: "/deleteUsers",
  GET_WEIGHT: "/weightData",
};

//暴露请求函数

//登录、注册
export const reqLogin = (data) => request.post(API.LOGIN_URL, data);
export const reqSign = (data) => request.put(API.SIGN_URL, data);
//获取用户信息
export const reqUserInfo = (id) => request.get(`${API.USERINFO_URL}/${id}`);
//获取验证码
export const reqImage = () => request.get(API.CAPTCHA_URL);
//获取收藏列表
export const reqGetFavoriteList = (data) =>
  request.post(API.GET_FAVORITE_URL, data);
//更新用户信息
export const reqUpdateInfo = (id, data) =>
  request.put(`${API.UPDATE_USERINFO_URL}/${id}`, data);
//收藏功能
export const reqAddFavorite = (data) =>
  request.post(
    `${API.ADD_FAVORITE_URL}?user_id=${data.userid}&meal_id=${data.meal_id}`
  );

export const reqGetAge = () => request.get(API.GET_AGE);

export const reqGetLoginSign = () => request.get(API.GET_LOGIN_SIGN);

export const reqGetGender = () => request.get(API.GET_USER_GENDER);

export const reqGetAllUser = (data) =>
  request.get(
    `${API.GET_ALL_USER}?page=${data.page}&size=${data.size}&name=${data.name}`
  );
export const reqRecordWeight = (data) =>
  request.put(
    `${API.RECORD_WEIGHT}?user_id=${data.user_id}&weight=${data.weight}&date=${data.date}`
  );

export const reqDeleteUser = (id) => request.delete(`${API.DELETE_USER}/${id}`);

export const reqDeleteUsers = (idlist) =>
  request.delete(API.DELETE_USERS, { data: idlist });

export const reqGetWeight = (id) => request.get(`${API.GET_WEIGHT}/${id}`);
